import React, { Component } from 'react';
import Son1 from './Son1';
import Son2 from './Son2';
// 引入会报错的组件
import Error from './Error';
// 引入错误边界的组件
import Boundaries from './Boundaries'

class Father extends Component {
  constructor() {
    super()
    this.state = {
      info: '你好，我是父组件',
      msg: '今天真冷'
    }
  }
  changeState() {
    this.setState({
      info: 'h1~我是父组件'
    })
  }
  render() {
    return (
      <div>
        <button onClick={() => this.changeState()}>修改父组件</button>
        <p>{this.state.info}</p>
        <Son1 msg={this.state.msg}></Son1>
        <hr />
        <Son2 msg={this.state.msg}></Son2>
        {/* 用边界组件，包裹会报错的组件 */}
        <Boundaries>
          <Error></Error>
        </Boundaries>
      </div>
    );
  }
}

export default Father;
